﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Utils;

namespace StriveEngine.SimpleDemoServer.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        public ContentResult Test1()
        {
            //var w = HttpContext.Current.Request;
            string echostr = Request["echostr"];
            HttpHelper httpHelper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.Method = "POST";
            item.URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ZTWPzo2e841QUtWYp2J13Z_j9HT3G8nzxXTsyK8lsCyT1CnNO5-5fW_QGBNflewYmBnLMu464bEiCmTdl8OCaJQwzqdaDYOJ9uSY5UASKrVM6kPluTGosIOC3GcVbs43MKJfAIAXVU";
            item.Postdata = saveLoad();
            HttpResult result = httpHelper.GetHtml(item);
            System.Drawing.Image image = Utils.ImageByteHelper.ReturnPhoto(result.ResultByte);
            image.Save("d:/1.jpg");
            return Content(echostr);
        }
        private string saveLoad()
        {
            StringWriter sw = new StringWriter();
            JsonWriter writer = new JsonTextWriter(sw);
            writer.WriteStartObject();
            writer.WritePropertyName("path");
            writer.WriteValue("pages/index/index");
            writer.WritePropertyName("width");
            writer.WriteValue(430);
            writer.WriteEndObject();
            writer.Flush();
            string jsonText = sw.GetStringBuilder().ToString();
            return jsonText;
        }
    }
}